//
//  NSObject+HDMessageModel.m
//  app
//
//  Created by D on 15/5/26.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDMessageModel.h"
#import "HDMessageCell.h"

@implementation HDMessageModel

-(instancetype)initWithDict:(NSDictionary *)dict
{
    if (self = [super init]) {
        
        CGFloat rightWight = UBO_WINDOW.width - UF(24)*4-UF(88)*2;
        
        self.uid = dict[@"uid"];
        self.fuid = dict[@"fuid"];
        NSString * str = dict[@"content"];
        self.content = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//        self.content = dict[@"content"];
        self.msgid = dict[@"msgid"];
        self.time = dict[@"dateline"];
        self.pmid = dict[@"pmid"];
        self.picture = dict[@"picture"];
        self.myType = dict[@"mtype"];
        self.lastid = dict[@"lastid"];
        self.type = dict[@"type"];
        
        
        
        
        if ([dict[@"flower"]length]>0) {
            self.flower = dict[@"flower"];
            self.red = dict[@"red"];
        }else
        {
            self.flower = @"00";
            self.red = @"00";
        }
        
//        DLog(@"model-type = %@",self.type);
        
        
        if (self.myType.integerValue == 3) {
            self.extends = dict[@"extends"];
            self.textHeight = 120.0f;
            
        }else
        {
            self.extends = @{@"0":@"0"};
            
            if (self.picture.length !=0) {
                self.imageH = dict[@"height"];
                self.imageW = dict[@"width"];
                
                self.textHeight = 120;
                
            }else
            {
                
                
                CGFloat width = [self.content boundingRectWithSize:CGSizeMake(100000, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.width;
                
                if (width > rightWight) {
                    self.textWight = rightWight;
                    self.textHeight = [XCommon heightForString:self.content fontSize:14 andWidth:rightWight];
                }else
                {
                    self.textWight = [XCommon widthForString:self.content fontSize:14];
                    self.textHeight = [XCommon heightForString:self.content fontSize:14 andWidth:self.textWight];
                }
                
//                DLog(@"wight = %f  higth = %f",self.textWight,self.textHeight);
            }
        }

        
        
        
        
        
    }
    
    
    return self;
}

+(instancetype)modelWithDict:(NSDictionary *)dict
{
    return [[self alloc] initWithDict:dict];
}

@end
